require('../../assets/css/index.less')
require('./group.less')
require('../../assets/js/property')
const renderTabbar = require('../../intils/tabbar.js')
const request = require('../../intils/reques')
// 服务器地址
const url = 'http://fitness.h5.itsource.cn:3701'




window.onload = () => {
    renderTabbar()
    // 获取课程数据
    function getCur() {
        request.get('/api/train/courseList')
            .then(res => {
                let { errno, data } = res.data
                console.log(data);
                if (errno === 0) {
                    $('#img1').src = url + data[0].imgurl
                    $('#title').textContent = data[0].name
                    $('#miaoshu').textContent = data[1].desc
                }
            })




    }
    getCur()











    // 获取圈子数据
    function getData() {
        request.get('/api/circles/opinionList')
            .then(res => {
                console.log(res.data);
                let { errno, data } = res.data
                if (errno === 0) {
                    // console.log(data[0].imgUrls[0]);
                    render(data)
                }


            })




    }
    getData()
    // 渲染数据
    function render(data) {
         //获取课程列表数据
         const data1 = data.filter((v, i) => i < 3)
         
         
        // 定义html代码片段
        let html = `
        ${data1.map(v =>
            `
            <div class="df dynamic-box1">
            <img  alt="" class="first" src="${url + v.imgUrls[0]}">
            <div class="df fdc jcc">
                <span></span>
                <span class="city"></span>
            </div>
        </div>
        <div class="dynamic-box2">
            ${v.content}
        </div>
        <div class="dynamic-box3 df jcsb">
            <img  alt="" src="${url + v.imgUrls[0]}">
            <img  alt="" src="${url + v.imgUrls[0]}">
            <img  alt="" src="${url + v.imgUrls[0]}">
            <img  alt="" src="${url + v.imgUrls[0]}">
            <img  alt="" src="${url + v.imgUrls[0]}">
            <img  alt="" src="${url + v.imgUrls[0]}">
        
            `
        ).join('')}
        `
        // 渲染到页面
        $('.dynamic').innerHTML=html
    }

    //获取课程列表
    function getList(){
        request.get('/api/train/courseList')
            .then(res => {
                let { errno, data } = res.data
                console.log(res.data);
                if (errno === 0) {
                    $('#recommend').href=`./course-details.html?id=${data[0].courseId}`
                }
            })

    } 
    getList()


}